package com.neutech.neusys.controller;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.neutech.neusys.service.DeptService;
import com.neutech.po.Dept;
import com.neutech.vo.ViewData;

@RestController
@RequestMapping("/deptmage")
/*public class DrugController {
	@RequestMapping(value="addNewDrug",method=RequestMethod.POST)
	public String addNewDrug(@RequestBody Drug drug){
		System.out.println(drug.getDrugsName());
		return "success";
	}
}*/
//方法二  不用写bean（实体类）
public class DeptController {
	@Autowired DeptService deptService;
	@RequestMapping(value="/addNewDept",method=RequestMethod.POST)
	public Dept addNewDept(@RequestBody Map<String,Object> dept){
		System.out.println(dept.get("deptName"));
		deptService.addNewDept(dept);
		Dept redept = new Dept();
		redept.setDeptName("haha");
		return redept;
	}
	
	@RequestMapping(value="/updatedept",method=RequestMethod.POST)
	public Dept updateDept(@RequestBody Map<String,Object> dept){
		System.out.println(dept.get("DeptName"));
		deptService.updateDept(dept);
		Dept redrug = new Dept();
		redrug.setDeptName("ok");
		return redrug;
	}
	
	@RequestMapping(value="/deletdept",method=RequestMethod.GET)
	public String deletdept(Dept dept){
		int result = deptService.deletdept(dept);
		if(result == 1){
			return "删除成功";
		}else{
			return "删除失败";
		}
	}
	
	@RequestMapping(value="/getDept")
	public ViewData getDept(@RequestParam Map<String,Object> map){
		/*System.out.println(map.get("pageNumber"));
		System.out.println(map.get("DrugsName"));*/
		return deptService.getdept(map);
	}
}
